package com.qianfeng.xinyihezi.xinyihezi.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.qianfeng.xinyihezi.xinyihezi.R;
import com.qianfeng.xinyihezi.xinyihezi.activity.ShowActivity;
import com.qianfeng.xinyihezi.xinyihezi.model.AllBean;

import java.util.List;

/**
 * 作者：王加威 on 2016/11/13 19:11
 */

public class MyRecyclerViewAdapter extends RecyclerView.Adapter  {
    private Context mContext;
    private List<AllBean.DataBean.ActivityBean.GoodsBean> mGoodses;

    public MyRecyclerViewAdapter(Context context, List<AllBean.DataBean.ActivityBean.GoodsBean> goodses) {
        mContext = context;
        mGoodses = goodses;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.goods_items,null);
        RecyclerView.ViewHolder holder=new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder= (ViewHolder) holder;
        Glide.with(mContext).load(mGoodses.get(position).image_url).into(viewHolder.mImageView);
        final int po = position;
        viewHolder.mImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(mContext, ShowActivity.class);
//        intent.putExtra("url","http://app.xinyihezi.com:8888/good/?goodid="+mGoodses.get(position).goods_id+"&app_ver=2.4.0&mac=B8%3A70%3AF4%3A10%3A6F%3A4E&unique_id=864394010184705&channel_src=wandoujia&from_type=Android");
                intent.putExtra("url",mGoodses.get(po).html_src);
                intent.putExtra("id",mGoodses.get(po).goods_id);
                intent.putExtra("title", mGoodses.get(po).short_name);
                intent.putExtra("imageUrl", mGoodses.get(po).image_url);
                mContext.startActivity(intent);
            }
        });
        viewHolder.mTextView1.setText(mGoodses.get(position).short_name);
        viewHolder.mTextView2.setText(mGoodses.get(position).p_price);
    }

    @Override
    public int getItemCount() {
        return mGoodses ==null?0: mGoodses.size();
    }


    public  static  class ViewHolder extends RecyclerView.ViewHolder{
        private ImageView mImageView;
        private TextView mTextView1,mTextView2;
        public ViewHolder(View itemView) {
            super(itemView);
            mImageView= (ImageView) itemView.findViewById(R.id.goods_item_iv);
            mTextView1= (TextView) itemView.findViewById(R.id.goods_item_tv1);
            mTextView2= (TextView) itemView.findViewById(R.id.goods_item_tv2);
        }
    }
}
